//
// Created by YANHAI on 2020/2/25.
//

#include <iostream>
#include <boost/program_options.hpp>

using namespace std;
using namespace boost::program_options;

namespace bpo = boost::program_options;

std::string showstring(std::string &str)
{
    std::cout << str << std::endl;
    return std::string(str + ";");
}

int main(int argc, char *argv[])
{
    bpo::options_description app_options("APP options");
    app_options.add_options()
            ("help,h", "Print this help message and exit.")
            ("num", bpo::value<uint32_t>()->required()->multitoken(), "int")
            ("w", bpo::value<std::vector<std::string>>(), "string");

    bpo::variables_map options;
    bpo::store(bpo::parse_command_line(argc, argv, app_options), options);

    if (argc == 1 || options.count("help")) {
        std:cout << app_options << std::endl;
        return 0;
    }

    bpo::notify(options);

    if (options.count("num")) {
        std::cout << "num " << options["num"].as<uint32_t>() << std::endl;
    }
    if (options.count("word")) {
        std::vector<std::string> words = options["word"].as<std::vector<std::string>>();
        std::transform(words.begin(), words.end(), words.begin(), showstring);

        for (const auto &itr : words) {
            std::cout << "===> " << itr << std::endl;
        }
    }

    return 0;
}
